<?php 
	$userInfo = $this->Session->read('Auth');
	
	$isLoggedIn = isset($userInfo['User']['id']) ? 1 : 0;
	
	if ($isLoggedIn) {
		$mainMenuInfo = Configure::read('MAIN_MENU_MASTER');
		$subMenuInfo = Configure::read('SUB_MENU_MASTER');
	
		//unset($subMenuInfo[0][0]);
		
		$activeMainMenuId = isset($active_main_menu_id) ? $active_main_menu_id : 0;
		$activeSubMenuId = isset($active_sub_menu_id) ? $active_sub_menu_id : 0;
	} else {
		$mainMenuInfo = array(0 => 'Users');
		$subMenuInfo = array(
			0 => array(
				0 => array(
					'text' => 'Login',
					'link' => array('controller' => 'users', 'action' => 'login')
					)				
				)
			);
			
		$activeMainMenuId = 0;
		$activeSubMenuId = 0;
	}
?>
	
<ul class="accordion">
	<?php foreach ($mainMenuInfo as $mainMenuId => $mainMenuName) {?>
		<li id="main-menu-<?php echo $mainMenuId;?>">
			<?php 
				echo $this->Html->link(
					$mainMenuName ,
					array('#main-menu-' . $mainMenuId),
					array('escape' => false, 'class' => ($mainMenuId == $activeMainMenuId) ? 'active' : '')
				);
			?>
			
			<ul class="sub-menu">
				<?php foreach ($subMenuInfo[$mainMenuId] as $subMenuId => $subMenuArr) {?>
					<li>
						<?php 
							echo $this->Html->link(
								$subMenuArr['text'],
								$subMenuArr['link'],
								array('class' => (($mainMenuId == $activeMainMenuId) && ($subMenuId == $activeSubMenuId)) ? 'active' : '')
							)
						?>
					</li>
				<?php }?>
			</ul>
		</li>
	<?php }?>
</ul>

<script type="text/javascript">
	var activeMainMenuId = parseInt("<?php echo $activeMainMenuId?>");
</script>

<?php echo $this->Html->script('menu_accordion');?>